/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.agile.gcodeviewer;

/**
 *
 * @author Rko
 */
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import javax.imageio.ImageIO;

public class WriteImageType {
  static public void main(String args[]) throws Exception {
    try {
      int width = 15000, height = 15000;

      // TYPE_INT_ARGB specifies the image format: 8-bit RGBA packed
      // into integer pixels
      BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

      Graphics2D ig2 = bi.createGraphics();

int oldx = 0, oldy =0;
      Font font = new Font("TimesRoman", Font.BOLD, 20);
      //ig2.setFont(font);
      //String message = "www.java2s.com!";
      //FontMetrics fontMetrics = ig2.getFontMetrics();
      //int stringWidth = fontMetrics.stringWidth(message);
      //int stringHeight = fontMetrics.getAscent();
      ig2.setPaint(Color.white);
      //ig2.drawString(message, (width - stringWidth) / 2, height / 2 + stringHeight / 4);
      
      
      
      
      File file = new File("E:\\agile-pipei\\gcode");
        String line;

        try (BufferedReader input = new BufferedReader(new FileReader(file))) {
            line = input.readLine();
            while (line != null) {
                if (line.charAt(0) == 'X') {
                    String strx = line.split("X")[1];
                    System.out.println(strx);
                    String[] x = strx.split("Y");
                   
                    
                     int intx = Integer.parseInt(x[0]);
                     System.out.println(intx);//X
                    strx = x[1];
                    String[] y = strx.split("D");
                    
                    strx = y[1];
                     int inty = Integer.parseInt(y[0]);
                     System.out.println(inty);//Y
                    String[] d = strx.split("\\*");
                    System.out.println(d[0]);//D
                    
                    ig2.drawLine(oldx, oldy, intx, inty);
                        oldx = intx;
                        oldy = inty;
                }
                line = input.readLine();
            }
        } catch (IOException e) {

        }
      
      

      //ImageIO.write(bi, "PNG", new File("c:\\yourImageName.PNG"));
      ImageIO.write(bi, "JPEG", new File("e:\\yourImageName.JPG"));
      //ImageIO.write(bi, "gif", new File("c:\\yourImageName.GIF"));
      //ImageIO.write(bi, "BMP", new File("c:\\yourImageName.BMP"));
      
    } catch (IOException ie) {
      ie.printStackTrace();
    }

  }
}
